<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############



$tables = array();
$allTables = $DB->fetchAll("SHOW TABLES");

foreach($allTables as $k=>$v){
    foreach($v as $key=>$tablename){
        $tables[] = $tablename;
    }
}

$tables = implode(',', $tables);

$queries = file_get_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.'tables.sql');
$queries = str_replace('prefix_', $CONFIG->dbprefix, $queries);
$queries = str_replace('__tables__', $tables, $queries);
$queries = explode(';', $queries);

foreach($queries as $k=>$q){
    if(trim($q)=='') continue;
    $DB->query($q);
}




$this->createPermission('perm_jfxbup_restore');
$this->createPermission('perm_jfxbup_settings');


$this->resetLanguages();

$unix = false;
$windows = false;

switch(strtolower(PHP_OS)){
    case 'freebsd':
    case 'linux':
    case 'netbsd':
    case 'openbsd':
    case 'unix':
        $unix = true;
    case 'winnt':
    case 'windows':
        $windows = true;
    default:


}

if($unix || $CONFIG->baseDir{0}=='/'){
    // probably unix
    $output = array();
    exec('which mysqldump', $output);
    if(count($output)==0){
        // will not work if cannot find mysqldump
        $DB->update($CONFIG->dbprefix.$this->keyname.'_config', array('v'=>'unknown'), "k = 'operating_system'");
    }else{
        if(strlen($output[0])>0) $output[0] = rtrim($output[0], '/');
        else $output[0] = 'mysqldump';
        $DB->update($CONFIG->dbprefix.$this->keyname.'_config', array('v'=>$output[0]), "k = 'path_to_mysqldump'");
        $DB->update($CONFIG->dbprefix.$this->keyname.'_config', array('v'=>'unix'), "k = 'operating_system'");
    }
    
}elseif($windows || true){
    // probably windows, marked as unknown due to heavy task finding mysqldump.exe, this should be configured manually
    $DB->update($CONFIG->dbprefix.$this->keyname.'_config', array('v'=>'unknown'), "k = 'operating_system'");
}












